package com.example.dingdong.websocketConfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.*;

import com.example.dingdong.websocketHandler.MyHandler;
import com.example.dingdong.websocketInterceptor.MyWebSocketInterceptor;
import com.example.dingdong.websocketService.WebSocketService;



@Configuration
@EnableWebSocket
public class WebSocketConfig implements  WebSocketConfigurer {

    @Bean
    public MyHandler webSocketHandler() {
        return new MyHandler();
    }
    @Bean
	public  MyWebSocketInterceptor getWSHandshakeInterceptor() {
		return new MyWebSocketInterceptor();
	}

	@Bean
	public WebSocketService getWebSocketService() {
		return new WebSocketService();
	}
	
	@Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
    	webSocketHandlerRegistry.addHandler(webSocketHandler(), "/wsresult").setAllowedOrigins("*")
		.addInterceptors(getWSHandshakeInterceptor());
    }

}
